package com.demo.crm.springboot3security.entity;

import java.time.LocalDateTime;

import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.RelationManyToOne;
import com.mybatisflex.annotation.Table;

import lombok.Data;

/**
 * 表单字段值实体
 * 用于存储大文本字段和不常用字段的值
 */
@Data
@Table("form_field_values")
public class FormFieldValue {
    @Id(keyType = KeyType.Auto)
    private Long id;

    private Long recordId;      // 关联到主记录的ID

    @Column("form_id")
    private Long formId;

    @RelationManyToOne(selfField = "formId", targetField = "id")
    private CustomForm form;

    // 关联到主记录的ID
    @Column("field_id")
    private Long fieldId;

    @RelationManyToOne(selfField = "fieldId", targetField = "id")
    private FormField field;

    private String textValue;   // 文本值

    private Long numberValue;   // 数字值

    private LocalDateTime dateValue;  // 日期时间值

    private Boolean booleanValue;    // 布尔值

    private LocalDateTime createdAt;

    private LocalDateTime updatedAt;

    public void prePersist() {
        this.createdAt = LocalDateTime.now();
        this.updatedAt = LocalDateTime.now();
    }

    public void preUpdate() {
        this.updatedAt = LocalDateTime.now();
    }
}